//
//  AuthenTopTypeCompanyVM.swift
//  kxf
//
//  Created by Mac on 2024/3/8.
//

import Foundation
import UIKit

enum COMPANY_AUTHEN_MSG_TYPE {
    case merc
    case legal
    case settle
    case market
}

class AuthenTopTypeCompanyVM: UIView {
    
    let selfHeight = kFitWidth(44)
    
    var type = COMPANY_AUTHEN_MSG_TYPE.merc
    var typeChangeBlock:((COMPANY_AUTHEN_MSG_TYPE)->())?

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var merchantMsgVM : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "商户信息"
        vm.setSelected(isSelect: true)
        vm.tapBlock = {()in
            if self.type != .merc{
                self.type = .merc
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
    lazy var legalMsgVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: SCREEN_WIDHT*0.25, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "法人信息"
        vm.tapBlock = {()in
            if self.type != .legal{
                self.type = .legal
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
    lazy var settleMsgVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: SCREEN_WIDHT*0.5, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "结算信息"
        vm.tapBlock = {()in
            if self.type != .settle{
                self.type = .settle
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
    lazy var marketMsgVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: SCREEN_WIDHT*0.75, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "门店信息"
        vm.tapBlock = {()in
            if self.type != .market{
                self.type = .market
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
}

extension AuthenTopTypeCompanyVM{
    @objc func typeChangeAction() {
        if self.typeChangeBlock != nil{
            self.typeChangeBlock!(self.type)
        }
    }
    func setBtnNormal() {
        self.legalMsgVm.setSelected(isSelect: self.type == .legal ? true : false)
        self.settleMsgVm.setSelected(isSelect: self.type == .settle ? true : false)
        self.merchantMsgVM.setSelected(isSelect: self.type == .merc ? true : false)
        self.marketMsgVm.setSelected(isSelect: self.type == .market ? true : false)
    }
    func setTypeSelected(type:COMPANY_AUTHEN_MSG_TYPE) {
        self.type = type
        self.legalMsgVm.setSelected(isSelect: self.type == .legal ? true : false)
        self.settleMsgVm.setSelected(isSelect: self.type == .settle ? true : false)
        self.merchantMsgVM.setSelected(isSelect: self.type == .merc ? true : false)
        self.marketMsgVm.setSelected(isSelect: self.type == .market ? true : false)
    }
}
extension AuthenTopTypeCompanyVM{
    func initUI() {
        addSubview(merchantMsgVM)
        addSubview(legalMsgVm)
        addSubview(settleMsgVm)
        addSubview(marketMsgVm)
    }
}

